package com.example.demo.six;

import com.example.demo.util.RabbitMQUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;

/**
 * @author chensixiang chensixiang1234@gmail.com
 */
public class ReceiveLogs04 {

    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws IOException {
        Channel channel = RabbitMQUtils.getChannel();

        // 扇出， 广播
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        channel.queueDeclare("disk", false, false, false, null);

        // 绑定
        channel.queueBind("disk", EXCHANGE_NAME, "error");
        System.out.println("C2等待接收消息，把接受到的消息打印在屏幕上");

        channel.basicConsume("disk", true, (consumerTag, message) -> {
            System.out.println("接受消息 -> " + new String(message.getBody()));
        }, (consumerTag, sig) -> {
        });

    }

}
